package com.example.spring_ioc.Controller;

import com.example.spring_ioc.Configuration.StudentConfig;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Controller
@ResponseBody
public class YmlController {
    @Value("${spring.datasource.url}")
    public String url;
    @Value("${spring.datasource.username}")
    public String username;

    @Value("${string.str1}")
    public String str1;
    @Value("${string.str2}")
    public String str2;
    @Value("${string.str3}")
    public String str3;

    @Autowired // 将对象注入进来
    public StudentConfig studentConfig;

    @PostConstruct //
    public void readValue() {
//        System.out.println(url);
//        System.out.println(username);
//        System.out.println(str1);
//        System.out.println(str2);
//        System.out.println(str3);
    }

    @RequestMapping("/readObject")
    public String readObject() {
        return studentConfig.toString();
    }
}
